package nGui.controls.containers;

import nGui.controls.ReturnType;
import nGui.controls.Control;

enum DialogSize
{
	FULL;
	HALF;
	THIRD;
	QUARTER;
	EIGHTH;
	DYNAMIC;
}

class Dialog extends Control
{
	public var onClose(default,close) : Void -> Void;
	public var showmin(null,minBox) : Bool;
	public var showmax(null,maxBox) : Bool;
	public var title(null,setTitle) : String;
	public var menu(null,setMenu) : String;
	public var showmenubox(null,menuBox) : Bool;
	public var resizable(null,setResize) : Bool;
	public var fullscreen(null,setFullScreen) : Bool;
	public var modal(null,setModal) : Bool;
	public var traytip(null,setTrayTip) : String;
	public var bringtofront(null,setToFront) : Bool;
	public var hidetaskbar(null,hideFromTaskBar) : Bool;
	public var helpbutton(null,showHelp) : Bool;
	private var _w : DialogSize;
	private var _h : DialogSize;

	public function new( item : Control )
	{
		super();
		__c = ngui_dialog( item.__c );
	}

	public function appendChild( child : Control )
	{
		ngui_append_element( __c, child.__c );
	}

	public function show()
	{
		ngui_show( __c );
	}

	private function close( func : Void->Void )
	{
		Reflect.setField(this,"onClose",func);
		this.setCallback( "CLOSE_CB", onClose, DEFAULT );
		return func;
	}

	public function maxBox( show : Bool )
	{
		setAttribute( "MAXBOX", if ( show == true ) "YES" else "NO" );
		return null;
	}

	public function minBox( show : Bool )
	{
		setAttribute( "MINBOX", if ( show == true ) "YES" else "NO" );
		return null;
	}

	private function setTitle( val : String )
	{
		setAttribute( "TITLE", val );
		return null;
	}

	private function menuBox( show : Bool )
	{
		setAttribute( "MENUBOX", if ( show == true ) "YES" else "NO" );
		return null;
	}

	private function setResize( show : Bool )
	{
		setAttribute( "RESIZE", if ( show == true ) "YES" else "NO" );
		return null;
	}

	private function setFullScreen( full : Bool )
	{
		setAttribute( "FULLSCREEN", if ( full == true ) "YES" else "NO" );
		return null;
	}

	private function setModal( val : Bool )
	{
		setAttribute( "TOPMOST", if ( val == true ) "YES" else "NO" );
		return null;
	}

	private function setToFront( val : Bool )
	{
		setAttribute( "BRINGFRONT", if ( val == true ) "YES" else "NO" );
		return null;
	}

	private function showHelp( val : Bool )
	{
		setAttribute( "HELPBUTTON", if ( val == true ) "YES" else "NO" );
		return null;
	}

	private function hideFromTaskBar( val : Bool )
	{
		setAttribute( "HIDETASKBAR", if ( val == true ) "YES" else "NO" );
		return null;
	}

	private function setTrayTip( val : String )
	{
		setAttribute( "TRAYTIP", val );
		return null;
	}

	public function showTray()
	{
		setAttribute( "TRAY", "YES" );
		setAttribute( "TRAYICON", "YES" );
		return null;
	}

	public function setMenu( val : String )
	{
		setAttribute( "MENU", val );
		return null;
	}


	private function getSize( s : DialogSize )
	{
		return switch( s )
		{
			case FULL: "FULL";
			case HALF: "HALF";
			case THIRD: "THIRD";
			case QUARTER: "QUARTER";
			case EIGHTH: "EIGHTH";
			default: "NULL";
		}
	}

	public function setHeight( h : Dynamic )
	{
		setSize( getSize( _w ), getSize( h ) );
		return h;
	}

	public function getHeight() : Dynamic
	{
		return _h;
	}

	public function setWidth( w : Dynamic )
	{
		setSize( getSize( w ), getSize( _h ) );
		return w;
	}

	public function getWidth() : Dynamic
	{
		return _w;
	}



	static var ngui_dialog = neko.Lib.load("nGui","ngui_element_dialog",1);
	static var ngui_append_element = neko.Lib.load("nGui","ngui_append_element",2);
	static var ngui_show = neko.Lib.load("nGui","ngui_show_element",1);
}